<template>
  <fragment>
    <el-popover
      placement="bottom"
      width="240"
      trigger="click"
      popper-class="b-popover"
    >
      <el-row>
        <el-col :span="6" v-for="item in elementIcons" :key="item.index">
          <div class="j-icon">
            <i
              :class="item"
              @click="clickSelect(item)"
              :style="item === activeIcon ? 'color:#409EFF;' : ''"
            ></i>
          </div>
        </el-col>
      </el-row>
      <el-input
        slot="reference"
        v-model="activeIcon"
        placeholder="请选择图标"
        :prefix-icon="
          activeIcon == null || activeIcon == '' ? 'el-icon-search' : activeIcon
        "
        disabled
      ></el-input>
    </el-popover>
  </fragment>
</template>

<script>
import { elementIcons } from "@/components/IconPicker/lib/element-icon";

export default {
  name: "IconPicker",
  props: {
    model: {
      type: String,
      required: true,
    },
  },
  created() {
    const t = this;
    t.elementIcons = elementIcons;
    t.activeIcon = t.model;
  },
  data() {
    return {
      elementIcons: [],
      activeIcon: "",
    };
  },
  methods: {
    clickSelect(val) {
      const t = this;
      t.activeIcon = val;
      t.$emit("changeIcon", val);
    },
  },
};
</script>

<style>
.el-popover.b-popover {
  overflow-y: scroll;
  max-height: 260px !important;
  text-align: center;
}
</style>

<style lang="scss" scoped>
.j-icon {
  height: 32px;
  line-height: 32px;
  font-size: 16px;
}
</style>
